package com.vdm.util;

import java.util.Random;

public class RandomValidateCode {

	private Random random = new Random();
//	private String randString_num = "0123456789";// 随机产生的字符串
	private String randString_char = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生的字符串

	/*
	 * 获取随机的字符
	 */
	public String getRandomString(int num) {
		return String.valueOf(randString_char.charAt(num));
	}
	
	/**
	 * 生成四位验证码
	 * @return 四位验证码
	 */
	public String generate(){
		return generate(4);
	}
	
	/**
	 * 生成验证码
	 * @param count 验证码位数
	 * @return 
	 */
	public String generate(int count){
		String result = "";
		for(int i = 0; i < count; i++){
			result += String.valueOf(getRandomString(random.nextInt(randString_char.length())));
		}
		return result;
	}
	
	public static void main(String[] args) {
	}
	
}
